package com.yanqu.road.server.cmd.wineshop;

import com.yanqu.road.pb.wineshop.WineShopProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.wineshop.WineShopModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/7/20 18:23
 */
@Cmd(code = GameProtocol.S_WINESHOP_USE_POWER_ITEM, desc = "酒肆使用体力道具")
public class WineShopUsePowerAddItemCmd extends AbstractCommand {
    private int count;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WineShopProto.UserWineShopPowerAddItemReqMsg msg = WineShopProto.UserWineShopPowerAddItemReqMsg.parseFrom(packet.getBytes());
        count = msg.getCount();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(WineShopModule.class).useWineShopPowerAddItem(count);
    }

    @Override
    public void sendData(GamePlayer player) {
        WineShopProto.UserWineShopPowerAddItemRespMsg.Builder respMsg = WineShopProto.UserWineShopPowerAddItemRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_WINESHOP_USE_POWER_ITEM, respMsg);
    }
}
